# __author: Rachel章
# data: 2023/5/4
# desc: 供应商提现
import requests

from common.QwcCookieUtil import QwcCookieUtil
from common.config import getconf


class WithDrawal:

    # 收入提现列表
    def accout(self, env, phone):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-supplier-server/withdraw/getCount"
        headers = {"content-type": "application/json;charset=UTF-8", "Cache-control": "max-age=259200"}
        return requests.get(url, headers=headers, cookies=QwcCookieUtil.get_c(env, phone)).json()

    # 收入提现列表
    def query(self, env, phone,withdrawStatus="1",current=1,size=50):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-supplier-server/withdraw/getPageList"
        headers = {"content-type": "application/json;charset=UTF-8", "Cache-control": "max-age=259200"}
        dict = {
            "current": current,
            "size": size,
            "withdrawStatus": withdrawStatus #不传全部；1已结算待提现 2 提现申请中 3已提现到账
        }
        return requests.post(url, headers=headers, cookies=QwcCookieUtil.get_c(env, phone),json=dict).json()

    # 点击申请提现
    def apply(self, env,phone):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-supplier-server/withdraw/apply/create"
        headers = {"content-type": "application/json;charset=UTF-8","Cache-control":"max-age=259200"}
        return requests.post(url, headers=headers,cookies=QwcCookieUtil.get_c(env,phone)).json()

    # 取消申请提现
    def cancel(self, env,phone):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-supplier-server/withdraw/apply/cancel"
        headers = {"content-type": "application/json;charset=UTF-8","Cache-control":"max-age=259200"}
        return requests.post(url, headers=headers,cookies=QwcCookieUtil.get_c(env,phone)).json()

    # 确认提现
    def confirm(self, env, phone,id):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-supplier-server/withdraw/apply/confirm/%s"%id
        headers = {"content-type": "application/json;charset=UTF-8", "Cache-control": "max-age=259200"}
        return requests.post(url, headers=headers, cookies=QwcCookieUtil.get_c(env, phone)).json()

    # 商家后台审核列表
    def apply_list(self, env, qwc_token,auditStatus="1",current=1,size=50):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-retail-order-server/supplier/withdraw/getPageList"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": qwc_token}
        dict = {
            "current": current,
            "size": size,
            "auditStatus": auditStatus #不传全部；1待审核 9 已打款
        }

        return requests.post(url, headers=headers, json=dict).json()

    # 商家后台提现审核记录详情
    def apply_detail(self, env, qwc_token,id):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-retail-order-server/supplier/withdraw/getDetail/"+str(id)
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": qwc_token}
        return requests.get(url, headers=headers).json()

    # 商家后台提现审核记录详情打款列表
    def apply_detail_list(self, env, qwc_token, auditStatus="1", current=1, size=50):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-retail-order-server/supplier/withdraw/getDetailPageList"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": qwc_token}
        dict = {
            "current": current,
            "size": size,
            "auditStatus": auditStatus  # 不传全部；1待审核
        }

        return requests.post(url, headers=headers, json=dict).json()

    # 审核通过提现申请
    def aduit_pass(self, env, qwc_token, id):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-retail-order-server/supplier/withdraw/audit/pass"
        headers = {"content-type": "application/json;charset=UTF-8", "token": qwc_token}
        dict = {
            "id": str(id),
            "auditMessage": "自动化测试审核通过"
        }
        return requests.post(url, headers=headers, json=dict).json()

    # 审核驳回提现申请
    def aduit_refuse(self, env, qwc_token, id):
        base_url = getconf(env, "qwc_url")
        url = base_url + "flashmall-retail-order-server/supplier/withdraw/audit/deny"
        headers = {"content-type": "application/json;charset=UTF-8", "token": qwc_token}
        dict = {
            "id": str(id),
            "auditMessage": "自动化测试审核驳回"
        }
        return requests.post(url, headers=headers, json=dict).json()
